/*#include"threadPool.h"
//子线程的入口函数
void*pthreadFunc(void*args)
{
    threadPool_t *pool = (threadPool_t*)args;
    while(1)
    {
        //访问共享资源加锁
        pthread_mutex_lock(&pool->mutex);
        //说明队列里面有netfd
        //这里我写成了if 但应该是while
        while(pool->taskQeuen.length == 0)
        {
            //解锁并且陷入等待
            //解锁 + 退出
            pthread_cond_wait(&pool->cond,&pool->mutex);
            break;
        }
        //如果大于0 带锁继续操作
        //将队列里的netfd拿出来
        printf("tid = %ld,worker thread got a task!\n",pthread_self());
        int netfd = pool->taskQeuen.pThead->netfd; //拿头部的
        deleHead(&pool->taskQeuen);
        pthread_mutex_unlock(&pool->mutex);
        //transfile(netfd)
        printf("this child is readdy\n");
        send(netfd,"helloworld\n",15,0);
        close(netfd);
    }
    pthread_exit(NULL);
}
int makeWorker(threadPool_t *pool)
{
    //创建子线程
    for(int i =0;i<pool->threadNum;i++)
    {
        pthread_create(&pool->pidArr[i],NULL,pthreadFunc,pool); //这里写成 &pool 所以没有取到值      
    }
    return 0;
}*/
#include "threadPool.h"
void *threadFunc(void *arg){
    printf("tid = %ld",pthread_self());
    threadPool_t * pthreadPool = (threadPool_t *)arg;
    while(1){
        pthread_mutex_lock(&pthreadPool->mutex);
        while(pthreadPool->taskQeuen.length == 0){
            pthread_cond_wait(&pthreadPool->cond, &pthreadPool->mutex);
        }
        printf("tid = %ld, worker thread got a task!\n",
               pthread_self());
        int netfd = pthreadPool->taskQeuen.pThead->netfd;
        deleHead(&pthreadPool->taskQeuen);
        pthread_mutex_unlock(&pthreadPool->mutex);
        //transFile(netfd);
        printf("pthread is begin\n");
        sleep(3);
        printf("pthread is over\n");
        close(netfd);
    }
    pthread_exit(NULL);
}
int makeWorker(threadPool_t *pthreadPool){
    for(int i = 0; i < pthreadPool->threadNum; ++i){
        pthread_create(&pthreadPool->pidArr[i],NULL,
                       threadFunc, pthreadPool);
    }
    return 0;
}